/************************************************************/
/*															*/
/* $File      :  ObjectManager.h							*/
/* $Author    :  Sean Franklin								*/
/* $Info      :  X-Calibur Object Manager (See Info.txt)	*/
/*															*/
/************************************************************/


#ifndef _XCT_OM_
#define _XCT_OM_

#include <windows.h>
#include <vector>

class CXCTObj
{
public:

	CXCTObj(){ }
	virtual ~CXCTObj(){ }

	virtual bool Draw( void ){ return true; }
	virtual void Update( void ){ return; }

	int& GetIID(){ return ImageID; }
	RECT& GetBarrier(){ return barrier; }
	float& GetX(){ return x; }
	float& GetY(){ return y; }

	
	
protected:

	float x, y;
	
	RECT barrier;
	int ImageID;
};
static  BOOL CollidedWith(CXCTObj *a, CXCTObj *b) // dont know how else to get rid of the link error
{
	RECT temp = {0, 0, 0, 0};
	return (IntersectRect(&temp, &a->GetBarrier(), &b->GetBarrier()));	
}

class CObjectManager
{
public:

	CObjectManager(){ }
	~CObjectManager(){ }

	void AddObj(CXCTObj *obj){ objects.push_back(obj); }
	bool RenderAll(void)
	{
		for ( UINT i = 0; i < objects.size(); ++i )
			objects[i]->Draw();
	}
	CXCTObj *GetObjectByIID(int id)
	{
		for ( UINT i = 0; i < objects.size(); ++i )
		{
			if ( id == objects[i]->GetIID() )
				return objects[i];
		}
	}
	BOOL Contains ( CXCTObj *obj )
	{
		for ( std::vector<CXCTObj*>::iterator _itr = objects.begin(); _itr != objects.end(); ++_itr )
			if ( *_itr == obj )
				return TRUE;
		return FALSE;
	}
	void UpdateAll(void)
	{
		for ( UINT i = 0; i < objects.size(); ++i )
			objects[i]->Update();
	}

	void ClearOM()
	{
		objects.clear();
	}

private:

	std::vector<CXCTObj*> objects;
};


#endif